<?php
/**
 # com_jvframwork - JV Framework
 # @version		1.5.x
 # ------------------------------------------------------------------------
 # author    Open Source Code Solutions Co
 # copyright Copyright (C) 2011 joomlavi.com. All Rights Reserved.
 # @license - http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL or later.
 # Websites: http://www.joomlavi.com
 # Technical Support:  http://www.joomlavi.com/my-tickets.html
-------------------------------------------------------------------------*/

// Check to ensure this file is within the rest of the framework
defined('JPATH_BASE') or die();

/**
 * Renders a list element
 *
 * @package 	Joomla.Framework
 * @subpackage		Parameter
 * @since		1.5
 */

class JElementColorlist extends JElement
{
	/**
	* Element type
	*
	* @access	protected
	* @var		string
	*/
	var	$_name = 'Colorlist';

	/**
	 * JElementColorlist::fetchElement()
	 * 
	 * @param mixed $name
	 * @param mixed $value
	 * @param mixed $node
	 * @param mixed $control_name
	 * @return
	 */
	function fetchElement($name, $value, &$node, $control_name){
	    $theme = JVFactory::getFramework()->getActiveTheme()->theme;
		$class = ( $node->attributes('class') ? 'class="'.$node->attributes('class').'"' : 'class="inputbox"' );
        
        if(JFolder::exists(JPATH_ROOT.DS.'templates'.DS.'jv-framework'.DS.'themes'.DS.$theme.DS.'css'.DS.'colors'.DS))
        $files = JFolder::files(JPATH_ROOT.DS.'templates'.DS.'jv-framework'.DS.'themes'.DS.$theme.DS.'css'.DS.'colors'.DS,'css');
        
		$options = array ();
        if(isset($files) && count($files))
		foreach ($files as $i => $option)
		{
			$val	= str_replace('.css','',$option);
            if($i == 0 && (float)$value == -1 ){
                $value = $val;
            }
			$text	= $val;
			$options[] = JHTML::_('select.option', $val, '<span class="color-list" style="background-color: '.strtolower($text).'"></span>');
            
            if($val == $value || ($value == '-1' && $i == 0)){
                JFactory::getDocument()->addScriptDeclaration(
                "
                 window.addEvent('domready', function() {
                    $$('label[for={$control_name}{$name}{$value}]').addClass('active');
                 });
                "
                );
            }
		}
        
		return JHTML::_('select.radiolist',  $options, ''.$control_name.'['.$name.']', $class, 'value', 'text', $value, $control_name.$name);
	}
    
    public function fetchTooltip($name, $value, $xmlElement, $control_name) {
        return;
    }

}
